\chapter{String handling}

\section{strcmp}

\texttt{int32\_t strcmp(const char* s1, const char* s2)}

\subsection*{Description}
The function takes two parameters (s1 and s2) as strings and compares them.  \textbf{program\_name}
\subsection*{Parameters}
\begin{itemize}
 \item \textbf{s1}: first string to be compared
 \item \textbf{s2}: second string to be compared
\end{itemize}
\subsection*{Return values}
The function returns a \textbf{positive number} in the case  of s1 > s2, \textbf{0} in the case of s1 == s2 and a \textbf{negative number} for s1 < s2 
\subsection*{Examples}
 \begin{lstlisting}
char c[5];
do{
  lire(c,5);
  ecrire("\n");
}while(strcmp(c, "exit"));
...
if(!strcmp(EXIT, cmd)) {
 \end{lstlisting}

\section{strncat}

\texttt{char* strncat(char* s1, const char* s2, uint32\_t n)}

\subsection*{Description}
The function will concatenate two strings, s1 and s2. A third parameter \textbf{n}, is used to specify how many characters from s2 will be appended to s1, include the final \textbackslash0. 
\subsection*{Parameters}
\begin{itemize}
 \item \textbf{s1}: string to which the second string, s2 will be added
 \item \textbf{s2}: string to appended to s1 
 \item \textbf{n}: maximum length of characters to concatenate
\end{itemize}
\subsection*{Return values}
The function returns a pointer to s1.
\subsection*{Examples}
 \begin{lstlisting}
 strncat(buf, ": message went through ring: \"", MAX_STRING-strlen(buf));
 \end{lstlisting}

\section{strncpy}

\texttt{char* strncpy(char* destination, const char* source, uint32\_t n)}

\subsection*{Description}
The function will copy up to n characters from source to destination, including the final \textbackslash0. 
\subsection*{Parameters}
\begin{itemize}
 \item \textbf{destination}: the destination to which the source will be copied, of type \textit{char}.
 \item \textbf{source}: the source to be copied to the destination
 \item \textbf{n}: maximum length of characters to copy
\end{itemize}
\subsection*{Return values}
The function returns a pointer to the destination.
\subsection*{Examples}
 \begin{lstlisting}
strncpy(buf, "created process: ", MAX_STRING);
strncpy(text, m.data.str_data, 32);
 \end{lstlisting}

\section{strlen}

\texttt{int32\_t strlen(const char* s)}

\subsection*{Description}
The function will calculate the length of a given string s. 
\subsection*{Parameters}
\begin{itemize}
 \item \textbf{s}: the string of which the length is wanted
\end{itemize}
\subsection*{Return values}
The function returns an integer containing the length of string s.
\subsection*{Examples}
 \begin{lstlisting}
int len_param2 = strlen(param2);
strncat(s, buf, MAX_STRING-strlen(s));
 \end{lstlisting}

\section{atoi}

\texttt{int32\_t atoi(const char* string)}

\subsection*{Description}
The function converts string into an integer. string must only be composed of numbers for the function to work correctly. If atoi cannot convert string into an integer, it returns 0. 
\subsection*{Parameters}
\begin{itemize}
 \item \textbf{string}: the string to convert
\end{itemize}
\subsection*{Return values}
string converted into an integer or 0 if the conversion is not possible.
\subsection*{Examples}
 \begin{lstlisting}
 	atoi("123"); //returns 123
	atoi("ab1"); //returns 0
 \end{lstlisting}



\section{itoa}

\texttt{char* itoa(int32\_t value, char* string, uint32\_t n)}

\subsection*{Description}
This function converts value into a character string of at most n-1 characters. It creates a NULL terminated string. If string is not long enough, it returns value's n-1 rightmost numbers.
\subsection*{Parameters}
\begin{itemize}
	\item \textbf{value}: the integer to translate
 \item \textbf{string}: the destination string
 \item \textbf{n}: the maximal length of string (including the \textbackslash0 character)
\end{itemize}
\subsection*{Return values}
A pointer to string
\subsection*{Examples}
 \begin{lstlisting}
 	char buf[4];
	ecrire(itoa(42, buf, 4)); // prints 42
	ecrire(itoa(12345, buf, 4); // prints 345
 \end{lstlisting}


